//
//  TunerDetailCommentTableViewCell.m
//  TheRoadAD
//
//  Created by 宁宁 on 16/8/17.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "TunerDetailCommentTableViewCell.h"

@implementation TunerDetailCommentTableViewCell
{
    /**头像*/
    UIButton *_headImg;
    /**昵称*/
    UILabel *_name;
    /**评论时间*/
    UILabel *_time;
    /**评论*/
    UILabel *_comment;
    
    UIView *_line;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setCell];
    }
    return self;
}
- (void)setCell{
    //头像
    _headImg = [UIButton buttonWithType:UIButtonTypeCustom];
    _headImg.frame = CGRectMake(15, 15, 40, 40);
    _headImg.layer.cornerRadius = 20;
    _headImg.layer.masksToBounds = YES;
    [_headImg addTarget:self  action:@selector(jumpToUserHomePage) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_headImg];
    
    //昵称
    _name = [[UILabel alloc] initWithFrame:CGRectMake(_headImg.frame.origin.x + _headImg.frame.size.width + 10, _headImg.frame.origin.y, 1000, 16)];
    _name.font = [UIFont fontWithName:AppFont size:13];
    CGFloat nameX = _name.frame.origin.x;
    [self.contentView addSubview:_name];
    
    //时间
    _time = [[UILabel alloc] initWithFrame:CGRectMake(nameX + _name.frame.size.width + 10, _name.frame.origin.y + 2, 1000, 14)];
    _time.textColor = [UIColor lightGrayColor];
    _time.font = [UIFont fontWithName:AppFont size:11];
    [self.contentView addSubview:_time];
    
    //评论
    _comment = [[UILabel alloc] initWithFrame:CGRectMake(nameX, _name.frame.origin.y + _name.frame.size.height + 25, Screen_Width - nameX - 15, 1000)];
    _comment.font = [UIFont fontWithName:AppFont size:13];
    _comment.numberOfLines = 0;
    [self.contentView addSubview:_comment];

    _line = [[UIView alloc] initWithFrame:CGRectMake(0, _comment.frame.origin.y + _comment.frame.size.height + 10, Screen_Width, 2)];
    _line.backgroundColor = RGBColor(225, 225, 225);
    [self.contentView addSubview:_line];
}

- (void)setLayout:(NSArray *)userModel{
    //头像
    [_headImg setImage:[UIImage imageNamed:@"headImg.jpeg"] forState:UIControlStateNormal];
    
    //昵称
    _name.frame = CGRectMake(_headImg.frame.origin.x + _headImg.frame.size.width + 10, _headImg.frame.origin.y, 1000, 16);
    _name.text = userModel[0];
    _name.font = [UIFont fontWithName:AppFont size:13];
    [_name sizeToFit];
    CGFloat nameX = _name.frame.origin.x;
    if (Screen_Width - (_name.frame.size.width + _name.frame.origin.x) < 120) {
        _name.frame = CGRectMake(nameX, _headImg.frame.origin.y, Screen_Width - nameX - 120, 16);
    }
    [self.contentView addSubview:_name];
    
    //时间
    _time.frame = CGRectMake(nameX + _name.frame.size.width + 10, _name.frame.origin.y + 2, 1000, 14);
    _time.text = userModel[1];
    _time.textColor = [UIColor lightGrayColor];
    _time.font = [UIFont fontWithName:AppFont size:11];
    [self.contentView addSubview:_time];
    
    //评论
    _comment.frame = CGRectMake(nameX, _name.frame.origin.y + _name.frame.size.height + 25, Screen_Width - nameX - 15, 1000);
    _comment.text = userModel[2];
    _comment.font = [UIFont fontWithName:AppFont size:13];
    _comment.numberOfLines = 0;
    [_comment sizeToFit];
    [self.contentView addSubview:_comment];
    
    //分割线
    _line.frame = CGRectMake(0, _comment.frame.origin.y + _comment.frame.size.height + 10, Screen_Width, 2);
    
    CGFloat cellHeight = _line.frame.origin.y + _line.frame.size.height;
    
    _height = [NSString stringWithFormat:@"%f", cellHeight];
}





- (void)jumpToUserHomePage{
    _headImgClick();
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
